package com.zsr.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/***
 * 测试【请求转发】，从Servlet1转为Servlet2
 */
public class Servlet1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        System.out.println("在Servlet（柜台1）中查看参数（材料）："+username);

        //给材料盖一个章，并传递到Servlet2（柜台2）去查看
        request.setAttribute("key","柜台1的章");

        //问路 ：servlet2（柜台2）怎么走
        /**
         * 请求转发必须要以斜杠开头，/ 斜杠表示地址为 http://ip:port/工程名、 ,映射到IDEA代码的web目录
         */
        //【重点】
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/servlet2");
//        RequestDispatcher requestDispatcher2 = request.getRequestDispatcher("/WEB-INF/form.html");
        //走向柜台2
        requestDispatcher.forward(request,response);
    }
}
